package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.News;
import com.example.demo.mapper.NewsMapper;
import com.example.demo.service.NewsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
    private void updateByUrl(News news) {
        String url = news.getUrl();
        news.setUrl(null);
        super.update(news, new LambdaUpdateWrapper<News>().eq(News::getUrl, url));
    }

    @Override
    public void saveOrUpdateBatch(List<News> list) {
        if (list.size() == 1) this.updateByUrl(list.get(0));
        else super.saveBatch(list);
    }
}
